package com.best.oasis.settlement.dao.employee;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

import com.best.oasis.settlement.common.entity.employee.Employee;
import com.best.oasis.settlement.common.so.employee.EmployeeSO;
import com.best.oasis.settlement.dao.base.BaseDaoImpl;
import com.best.oasis.settlement.util.exception.QueryException;
import com.best.oasis.settlement.util.page.PageList;
@Repository
public class EmployeeDaoImpl extends BaseDaoImpl<Employee, Long> implements EmployeeDao {

	 
	private static final Log logger = LogFactory.getLog(EmployeeDaoImpl.class);
		
    public EmployeeDaoImpl(){
        super(Employee.class);
    }
    
    @SuppressWarnings("unchecked")
	public PageList<Employee> getPageList(EmployeeSO so) {
		PageList<Employee> result = new PageList<Employee>(so);
		List<Employee> list;
		int fullListSize;

        try {
            RowBounds rowBounds = new RowBounds((so.getPageNumber() - 1) * so.getObjectsPerPage(), so.getObjectsPerPage());
           
            list = (List<Employee>) sqlSessionTemplate.selectList(getStatementPrefix() + POSTFIX_GET_LIST_BY_SO ,so,rowBounds);
            fullListSize = getPaginatedListCount(so);
            
            result.setFullListSize(fullListSize);
            result.setList(list);
            
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e);
            throw new QueryException(e);
        } 
	}
}
